package jenkins

import (
	"log"
)

func GenerateJenkinsJobs(
	customerJobCreateParam CustomerJobCreateParam,
	backendJobCreateParam BackendJobCreateParam,
	adminJobCreateParam AdminJobCreateParam,
	// mobileJobCreateParam MobileJobCreateParam,
	dbJobCreateParam DBJobCreateParam,
	applicationRestartJobCreateParam ApplicationRestartJobCreateParam,
	) error {
	var err error

	// create view
	if isExists, err := IsJenkinsViewExists(customerJobCreateParam.EnvName); err != nil {
		log.Println(err)
		return err
	} else {
		if !isExists {
			// create view
			if err = CreateView(customerJobCreateParam.EnvName); err != nil {
				log.Println(err)
				return err
			}
		}
	}

	// create customer portal job
	if err = CreateCustomerPortalJob(customerJobCreateParam); err != nil {
		log.Println(err)
		return err
	}

	// create admin portal job
	if err = CreateAdminPortalJob(adminJobCreateParam); err != nil {
		log.Println(err)
		return err
	}

	// create backend job
	if err = CreateBackendJob(backendJobCreateParam); err != nil {
		log.Println(err)
		return err
	}

	// create db init job
	if err = CreateDBJob(dbJobCreateParam); err != nil {
		log.Println(err)
		return err
	}

	// create application restart job
	if err = CreateApplicationRestartJob(applicationRestartJobCreateParam); err != nil {
		log.Println(err)
		return err
	}
	return nil
}

